/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaGerenciaCidade.java
 *
 * Created on Jul 22, 2010, 2:47:39 AM
 */

package telas;
import controladoras.apresentacao.CntrIntCidade;
import controladoras.apresentacao.modelos.ModeloTabelaCidade;
/**
 *
 * @author thiagostuckert
 */
public class TelaGerenciaCidade extends javax.swing.JFrame {
    

    /** Creates new form TelaGerenciaCidade */
    public TelaGerenciaCidade() {
        initComponents();
    }

    private static TelaGerenciaCidade ref;
    public static TelaGerenciaCidade instanciar() {
        if(ref == null)
            ref = new TelaGerenciaCidade();
        return ref;
    }
    
    private CntrIntCidade cntrIntCidade;

    public void setControladoraInteracao(CntrIntCidade cntr){
        cntrIntCidade = cntr;
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        fechar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaCidade = new javax.swing.JTable();
        delCidade = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        addCidade = new javax.swing.JButton();
        nomeCidadeAdd = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        fechar.setText("Fechar");
        fechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fecharActionPerformed(evt);
            }
        });

        tabelaCidade.setModel(ModeloTabelaCidade.instanciar());
        jScrollPane1.setViewportView(tabelaCidade);

        delCidade.setText("Deleta Cidade");
        delCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delCidadeActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setText("Para editar uma cidade, basta clicar na \nlinha da cidade,modificar o nome, \napertar enter.\n");
        jScrollPane2.setViewportView(jTextArea1);

        addCidade.setText("Adiciona Cidade");
        addCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCidadeActionPerformed(evt);
            }
        });

        nomeCidadeAdd.setText("Nome da Cidade a Adicionar");
        nomeCidadeAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomeCidadeAddActionPerformed(evt);
            }
        });

        jLabel1.setText("Tela de Gerência de Cidade");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap(40, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(fechar)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jPanel1Layout.createSequentialGroup()
                            .add(31, 31, 31)
                            .add(nomeCidadeAdd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(delCidade)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 264, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addCidade))
                .add(29, 29, 29))
            .add(jPanel1Layout.createSequentialGroup()
                .add(172, 172, 172)
                .add(jLabel1)
                .addContainerGap(225, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 20, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 185, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(delCidade)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(30, 30, 30)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(nomeCidadeAdd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addCidade))
                .add(18, 18, 18)
                .add(fechar)
                .add(45, 45, 45))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fecharActionPerformed
        cntrIntCidade.encerrar();
}//GEN-LAST:event_fecharActionPerformed

    private void addCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCidadeActionPerformed
        cntrIntCidade.addCidade(nomeCidadeAdd.getText());
    }//GEN-LAST:event_addCidadeActionPerformed

    private void nomeCidadeAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nomeCidadeAddActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nomeCidadeAddActionPerformed

    private void delCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delCidadeActionPerformed
        cntrIntCidade.delCidade(tabelaCidade.getSelectedRow());
    }//GEN-LAST:event_delCidadeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addCidade;
    private javax.swing.JButton delCidade;
    private javax.swing.JButton fechar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField nomeCidadeAdd;
    private javax.swing.JTable tabelaCidade;
    // End of variables declaration//GEN-END:variables

}
